import 'package:flutter_admin/pages/common/cry/cry_all.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/api/odoo/dynamic_data_api.dart';
import 'package:flutter_admin/constants/constant.dart';
import 'package:flutter_admin/models/odoo/udt_tb_docmentstock.dart';
import 'package:flutter_admin/utils/store_util.dart';
import '../../../generated/l10n.dart';

class UdtTbFocmentstockDialog extends StatefulWidget {
  UdtTbFocmentstockDialog();

  @override
  _UdtTbFocmentstockDialogState createState() => _UdtTbFocmentstockDialogState();
}

class _UdtTbFocmentstockDialogState extends State<UdtTbFocmentstockDialog> {

  // late List<Widget> children;
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  UdtTbDocmentstock  udtTbDocmentstock = UdtTbDocmentstock();
  //文档类别
  late List<SelectOptionVO> docmenttypeList = [];
  //文档状态
  late List<SelectOptionVO> statusList = [];

  @override
  void initState() {
    var deparment = StoreUtil.read(Constant.KEY_CURRENT_USER_INFO)[0]["department_id"];
    udtTbDocmentstock.departmentId = deparment[0].toString();
    udtTbDocmentstock.departmentName = deparment[1].toString();
    super.initState();
    _loadData();
  }

  _loadData() async{
    docmenttypeList = await DynamicDataApi.getModelSelect(active:false,model: "dms.documenttype",name: "documenttypename",key: "department_id",val: int.parse(udtTbDocmentstock.departmentId!));
    statusList = [SelectOptionVO(value:'0',label: "入库"),SelectOptionVO(value:'1',label: "借出")];
    setState(() { });
  }

  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CryInput(
            label: '所属部门',
            enable: false,
            value: udtTbDocmentstock.departmentName,
          ),
          CrySelect(
            label: '档案项目',
            dataList: docmenttypeList,
            value: udtTbDocmentstock.documenttypeId,
            onSaved: (v) => {udtTbDocmentstock.documenttypeId = v},
          ),
          CryInput(
            // width: 280,
            label: '附件名称',
            value: udtTbDocmentstock.fileName,
            onSaved: (v) {
              udtTbDocmentstock.fileName = v;
            },
          ),
          CryInput(
            label: '档案盒名称',
            value: udtTbDocmentstock.documentname,
            onSaved: (v) {
              udtTbDocmentstock.documentname = v;
            },
          ),

          CrySelect(
            label: '状态',
            dataList: statusList,
            value: udtTbDocmentstock.status,
            onSaved: (v) {
              udtTbDocmentstock.status = v;
            },
          ),
          CryInput(
            label: '备注',
            value: udtTbDocmentstock.remark,
            onSaved: (v) {
              udtTbDocmentstock.remark = v;
            },
          ),
        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: "确定",
          onPressed: () {
            FormState form = formKey.currentState!;
            form.save();
            Navigator.pop(context, udtTbDocmentstock);
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("查询"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}